Load all required libraries.
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.8
## v tidyr 1.2.0 v stringr 1.4.0
## v readr 2.1.2 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(broom)
Read in raw data from RDS.
raw_data <- readRDS("./n1_n2_cleaned_cases.rds")
Make a few small modifications to names and data for visualizations.
final_data <- raw_data %>% mutate(log_copy_per_L = log10(mean_copy_num_L)) %>%
rename(Facility = wrf) %>%
mutate(Facility = recode(Facility,
"NO" = "WRF A",
"MI" = "WRF B",
"CC" = "WRF C"))
Seperate the data by gene target to ease layering in the final plot
#make three data layers
only_positives <<- subset(final_data, (!is.na(final_data$Facility)))
only_n1 <- subset(only_positives, target == "N1")
only_n2 <- subset(only_positives, target == "N2")
only_background <<-final_data %>%
select(c(date, cases_cum_clarke, new_cases_clarke, X7_day_ave_clarke)) %>%
group_by(date) %>% summarise_if(is.numeric, mean)
#specify fun colors
background_color <- "#7570B3"
seven_day_ave_color <- "#E6AB02"
marker_colors <- c("N1" = '#1B9E77',"N2" ='#D95F02')
#remove facilty C for now
#only_n1 <- only_n1[!(only_n1$Facility == "WRF C"),]
#only_n2 <- only_n2[!(only_n2$Facility == "WRF C"),]
only_n1 <- only_n1[!(only_n1$Facility == "WRF A" & only_n1$date == "2020-11-02"), ]
only_n2 <- only_n2[!(only_n2$Facility == "WRF A" & only_n2$date == "2020-11-02"), ]
Build the main plot
#first layer is the background epidemic curve
p1 <- only_background %>%
plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~new_cases_clarke,
type = "bar",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Daily Cases: ', new_cases_clarke),
alpha = 0.5,
name = "Daily Reported Cases",
color = background_color,
colors = background_color,
showlegend = FALSE) %>%
layout(yaxis = list(title = "Clarke County Daily Cases", showline=TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#renders the main plot layer two as seven day moving average
p1 <- p1 %>% plotly::add_trace(x = ~date, y = ~X7_day_ave_clarke,
type = "scatter",
mode = "lines",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Seven-Day Moving Average: ', X7_day_ave_clarke),
name = "Seven Day Moving Average Athens",
line = list(color = seven_day_ave_color),
showlegend = FALSE)
#renders the main plot layer three as positive target hits
p2 <- plotly::plot_ly() %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n1,
symbol = ~Facility,
marker = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
plotly::add_trace(x = ~date, y = ~mean_copy_num_L,
type = "scatter",
mode = "markers",
hoverinfo = "text",
text = ~paste('</br> Date: ', date,
'</br> Facility: ', Facility,
'</br> Target: ', target,
'</br> Copies/L: ', round(mean_copy_num_L, digits = 2)),
data = only_n2,
symbol = ~Facility,
marker = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(yaxis = list(title = "SARS CoV-2 Copies/L",
showline = TRUE,
type = "log",
dtick = 1,
automargin = TRUE)) %>%
layout(legend = list(orientation = "h", x = 0.2, y = -0.3))
#adds the limit of detection dashed line
p2 <- p2 %>% plotly::add_segments(x = as.Date("2020-03-14"),
xend = ~max(date + 10),
y = 3571.429, yend = 3571.429,
opacity = 0.35,
line = list(color = "black", dash = "dash")) %>%
layout(annotations = list(x = as.Date("2020-03-28"), y = 3.8, xref = "x", yref = "y",
text = "Limit of Detection", showarrow = FALSE))
p1
p2
Combine the two main plot pieces as a subplot
#seperate n1 and n2 frames by site
#n1
wrf_a_only_n1 <- subset(only_n1, Facility == "WRF A")
wrf_b_only_n1 <- subset(only_n1, Facility == "WRF B")
wrf_c_only_n1 <- subset(only_n1, Facility == "WRF C")
#n2
wrf_a_only_n2 <- subset(only_n2, Facility == "WRF A")
wrf_b_only_n2 <- subset(only_n2, Facility == "WRF B")
wrf_c_only_n2 <- subset(only_n2, Facility == "WRF C")
#rejoin the old data frames then seperate in to averages for each plant.
wrfa_both <- full_join(wrf_a_only_n1, wrf_a_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfb_both <- full_join(wrf_b_only_n1, wrf_b_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
wrfc_both <- full_join(wrf_c_only_n1, wrf_c_only_n2)%>%
select(c(date, mean_total_copies)) %>%
group_by(date) %>%
summarize_if(is.numeric, mean) %>%
ungroup() %>%
mutate(log_total_copies_both = log10(mean_total_copies))
## Joining, by = c("date", "new_cases_clarke", "cases_cum_clarke",
## "X7_day_ave_clarke", "Facility", "collection_num", "target",
## "mean_copy_num_uL_rxn", "mean_copy_num_L", "sd_L", "se_L", "mean_total_copies",
## "sd_total_copies", "lo_95", "up_95", "log_copy_per_L")
#get max date
maxdate <- max(wrfa_both$date)
mindate <- min(wrfa_both$date)
Build loess smoothing figures figures
This makes the individual plots
#**************************************WRF A PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_botha <- ggplot(wrfa_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_botha<<-..y..), method = "loess", color = '#1B9E77',
span = 0.25, n = 849)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_botha
## `geom_smooth()` using formula 'y ~ x'
fit_botha
## [1] 13.04616 13.04155 13.03700 13.03250 13.02804 13.02364 13.01930 13.01500
## [9] 13.01075 13.00656 13.00241 12.99831 12.99427 12.99027 12.98632 12.98242
## [17] 12.97857 12.97476 12.97101 12.96730 12.96364 12.96002 12.95646 12.95293
## [25] 12.94946 12.94603 12.94264 12.93931 12.93601 12.93276 12.92956 12.92640
## [33] 12.92328 12.92020 12.91717 12.91419 12.91124 12.90834 12.90548 12.90266
## [41] 12.89988 12.89714 12.89445 12.89180 12.88922 12.88671 12.88425 12.88186
## [49] 12.87953 12.87726 12.87505 12.87291 12.87082 12.86880 12.86684 12.86494
## [57] 12.86309 12.86131 12.85959 12.85793 12.85633 12.85478 12.85330 12.85188
## [65] 12.85051 12.84920 12.84795 12.84676 12.84562 12.84454 12.84352 12.84256
## [73] 12.84165 12.84080 12.84001 12.83927 12.83859 12.83796 12.83739 12.83687
## [81] 12.83641 12.83600 12.83565 12.83535 12.83511 12.83492 12.83478 12.83470
## [89] 12.83467 12.83469 12.83476 12.83489 12.83509 12.83540 12.83582 12.83633
## [97] 12.83693 12.83763 12.83842 12.83930 12.84026 12.84130 12.84242 12.84362
## [105] 12.84489 12.84622 12.84763 12.84910 12.85062 12.85221 12.85385 12.85554
## [113] 12.85728 12.85907 12.86090 12.86277 12.86468 12.86662 12.86859 12.87059
## [121] 12.87262 12.87467 12.87673 12.87882 12.88092 12.88303 12.88514 12.88726
## [129] 12.88939 12.89151 12.89363 12.89574 12.89784 12.89993 12.90200 12.90490
## [137] 12.90937 12.91524 12.92235 12.93054 12.93964 12.94950 12.95995 12.97082
## [145] 12.98197 12.99322 13.00441 13.01538 13.02597 13.03601 13.04535 13.05382
## [153] 13.06125 13.06750 13.07238 13.07575 13.07890 13.08320 13.08857 13.09491
## [161] 13.10215 13.11019 13.11896 13.12837 13.13833 13.14876 13.15958 13.17070
## [169] 13.18204 13.19351 13.20503 13.21651 13.22786 13.23902 13.24988 13.26036
## [177] 13.27039 13.27987 13.28872 13.29686 13.30420 13.31066 13.31615 13.32059
## [185] 13.32389 13.32597 13.32675 13.32614 13.32405 13.32067 13.31628 13.31093
## [193] 13.30467 13.29756 13.28964 13.28097 13.27161 13.26160 13.25100 13.23986
## [201] 13.22823 13.21616 13.20371 13.19093 13.17787 13.16459 13.15113 13.13755
## [209] 13.12390 13.11024 13.09661 13.08308 13.06968 13.05647 13.04352 13.03086
## [217] 13.01855 13.00506 12.98900 12.97058 12.95003 12.92758 12.90345 12.87788
## [225] 12.85110 12.82332 12.79478 12.76571 12.73633 12.70686 12.67755 12.64861
## [233] 12.62027 12.59276 12.56631 12.54115 12.51749 12.49558 12.47563 12.45788
## [241] 12.44088 12.42311 12.40465 12.38560 12.36605 12.34609 12.32581 12.30531
## [249] 12.28468 12.26400 12.24338 12.22290 12.20266 12.18275 12.16325 12.14427
## [257] 12.12589 12.10821 12.09132 12.07531 12.06026 12.04634 12.03354 12.02180
## [265] 12.01104 12.00117 11.99212 11.98380 11.97614 11.96906 11.96247 11.95630
## [273] 11.95047 11.94489 11.93949 11.93419 11.92891 11.92357 11.91809 11.91238
## [281] 11.90637 11.89999 11.89314 11.88575 11.87775 11.86904 11.85955 11.84973
## [289] 11.84006 11.83053 11.82116 11.81193 11.80285 11.79391 11.78512 11.77646
## [297] 11.76794 11.75955 11.75130 11.74317 11.73518 11.72731 11.71957 11.71195
## [305] 11.70445 11.69707 11.68981 11.68266 11.67563 11.66870 11.66121 11.65254
## [313] 11.64281 11.63215 11.62066 11.60847 11.59570 11.58245 11.56886 11.55504
## [321] 11.54110 11.52717 11.51335 11.49978 11.48656 11.47382 11.46167 11.45023
## [329] 11.43961 11.42995 11.42135 11.41392 11.40780 11.40310 11.39993 11.39841
## [337] 11.39866 11.39943 11.39946 11.39889 11.39783 11.39644 11.39482 11.39311
## [345] 11.39145 11.38995 11.38875 11.38798 11.38777 11.38824 11.38952 11.39175
## [353] 11.39505 11.39956 11.40539 11.41269 11.42157 11.43276 11.44673 11.46330
## [361] 11.48227 11.50346 11.52665 11.55167 11.57831 11.60639 11.63571 11.66607
## [369] 11.69728 11.72915 11.76148 11.79408 11.82675 11.85931 11.89155 11.92328
## [377] 11.95432 11.98446 12.01351 12.04127 12.06756 12.09218 12.11493 12.13562
## [385] 12.15406 12.17268 12.19388 12.21737 12.24290 12.27019 12.29897 12.32897
## [393] 12.35993 12.39156 12.42361 12.45581 12.48788 12.51955 12.55056 12.58063
## [401] 12.60950 12.63690 12.66255 12.68618 12.70754 12.72634 12.74231 12.75520
## [409] 12.76605 12.77611 12.78542 12.79400 12.80187 12.80907 12.81561 12.82153
## [417] 12.82685 12.83160 12.83581 12.83949 12.84268 12.84540 12.84768 12.84955
## [425] 12.85103 12.85215 12.85293 12.85340 12.85359 12.85353 12.85323 12.85274
## [433] 12.85206 12.85123 12.85028 12.84773 12.84227 12.83421 12.82384 12.81145
## [441] 12.79734 12.78180 12.76513 12.74762 12.72957 12.71128 12.69303 12.67512
## [449] 12.65785 12.64152 12.62641 12.61282 12.60106 12.59140 12.58415 12.57704
## [457] 12.56774 12.55646 12.54342 12.52883 12.51291 12.49587 12.47793 12.45929
## [465] 12.44018 12.42081 12.40139 12.38214 12.36327 12.34500 12.32753 12.31109
## [473] 12.29589 12.28214 12.27006 12.25986 12.25176 12.24596 12.24154 12.23743
## [481] 12.23362 12.23011 12.22691 12.22400 12.22140 12.21909 12.21709 12.21538
## [489] 12.21396 12.21285 12.21203 12.21150 12.21127 12.21133 12.21168 12.21233
## [497] 12.21327 12.21449 12.21601 12.21782 12.21991 12.22229 12.22496 12.22791
## [505] 12.23228 12.23908 12.24812 12.25920 12.27215 12.28677 12.30288 12.32028
## [513] 12.33879 12.35822 12.37837 12.39907 12.42012 12.44134 12.46253 12.48351
## [521] 12.50408 12.52407 12.54327 12.56151 12.57859 12.59433 12.60854 12.62102
## [529] 12.63159 12.64006 12.64625 12.64996 12.65256 12.65550 12.65874 12.66221
## [537] 12.66587 12.66967 12.67354 12.67745 12.68132 12.68512 12.68878 12.69226
## [545] 12.69550 12.69845 12.70105 12.70326 12.70501 12.70626 12.70695 12.70704
## [553] 12.70646 12.70516 12.70309 12.70020 12.69644 12.69174 12.68607 12.67936
## [561] 12.67079 12.65974 12.64643 12.63108 12.61390 12.59513 12.57498 12.55367
## [569] 12.53142 12.50846 12.48501 12.46128 12.43751 12.41391 12.39070 12.36810
## [577] 12.34634 12.32563 12.30621 12.28828 12.27207 12.25781 12.24571 12.23361
## [585] 12.21935 12.20311 12.18508 12.16545 12.14441 12.12215 12.09886 12.07473
## [593] 12.04995 12.02470 11.99918 11.97358 11.94808 11.92288 11.89816 11.87412
## [601] 11.85094 11.82881 11.80793 11.78848 11.77066 11.75464 11.74063 11.72880
## [609] 11.71936 11.71110 11.70273 11.69430 11.68586 11.67747 11.66918 11.66105
## [617] 11.65311 11.64544 11.63807 11.63106 11.62447 11.61834 11.61273 11.60769
## [625] 11.60327 11.59953 11.59652 11.59429 11.59289 11.59237 11.59279 11.59421
## [633] 11.59750 11.60336 11.61158 11.62191 11.63414 11.64803 11.66336 11.67989
## [641] 11.69740 11.71566 11.73444 11.75351 11.77264 11.79161 11.81019 11.82814
## [649] 11.84525 11.86127 11.87599 11.88917 11.90059 11.91183 11.92459 11.93873
## [657] 11.95416 11.97075 11.98840 12.00699 12.02641 12.04655 12.06729 12.08853
## [665] 12.11014 12.13203 12.15406 12.17614 12.19815 12.21998 12.24151 12.26263
## [673] 12.28323 12.30320 12.32242 12.34078 12.35818 12.37449 12.38960 12.40341
## [681] 12.41579 12.42743 12.43905 12.45064 12.46220 12.47370 12.48513 12.49648
## [689] 12.50773 12.51887 12.52988 12.54075 12.55148 12.56203 12.57240 12.58258
## [697] 12.59254 12.60228 12.61179 12.62104 12.63003 12.63873 12.64714 12.65524
## [705] 12.66302 12.67047 12.67756 12.68420 12.69033 12.69599 12.70121 12.70602
## [713] 12.71047 12.71460 12.71843 12.72201 12.72536 12.72854 12.73157 12.73450
## [721] 12.73735 12.74017 12.74299 12.74585 12.74878 12.75183 12.75502 12.75840
## [729] 12.76201 12.76587 12.76974 12.77335 12.77671 12.77984 12.78276 12.78546
## [737] 12.78797 12.79029 12.79245 12.79445 12.79631 12.79803 12.79964 12.80115
## [745] 12.80256 12.80389 12.80515 12.80637 12.80754 12.80868 12.80981 12.81078
## [753] 12.81147 12.81189 12.81206 12.81199 12.81170 12.81122 12.81055 12.80972
## [761] 12.80875 12.80764 12.80642 12.80511 12.80371 12.80226 12.80077 12.79925
## [769] 12.79773 12.79622 12.79473 12.79329 12.79191 12.79061 12.78941 12.78833
## [777] 12.78738 12.78645 12.78542 12.78430 12.78310 12.78181 12.78044 12.77899
## [785] 12.77747 12.77589 12.77423 12.77252 12.77076 12.76894 12.76708 12.76517
## [793] 12.76322 12.76124 12.75922 12.75718 12.75512 12.75303 12.75093 12.74882
## [801] 12.74670 12.74458 12.74247 12.74035 12.73825 12.73616 12.73406 12.73192
## [809] 12.72974 12.72753 12.72528 12.72300 12.72067 12.71831 12.71590 12.71346
## [817] 12.71097 12.70845 12.70588 12.70327 12.70062 12.69793 12.69519 12.69241
## [825] 12.68959 12.68672 12.68381 12.68085 12.67785 12.67483 12.67178 12.66869
## [833] 12.66557 12.66243 12.65924 12.65603 12.65278 12.64949 12.64617 12.64282
## [841] 12.63942 12.63599 12.63251 12.62900 12.62545 12.62185 12.61822 12.61454
## [849] 12.61081
#assign fits to a vector
both_trenda <- fit_botha
#extract y min and max for each
limits_botha <- ggplot_build(extract_botha)$data
## `geom_smooth()` using formula 'y ~ x'
limits_botha <- as.data.frame(limits_botha)
both_ymina <- limits_botha$ymin
both_ymaxa <- limits_botha$ymax
#reassign dataframes (just to be safe)
work_botha <- wrfa_both
#fill in missing dates to smooth fits
work_botha <- work_botha %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_botha <- work_botha$date
#create a new smooth dataframe to layer
smooth_frame_botha <- data.frame(date_vec_botha, both_trenda, both_ymina, both_ymaxa)
#WRF A
#plot smooth frames
p_wrf_a <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_botha, y = ~both_trenda,
data = smooth_frame_botha,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha,
'</br> Median Log Copies: ', round(both_trenda, digits = 2)),
line = list(color = '#1B9E77', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_botha, ymin = ~both_ymina, ymax = ~both_ymaxa,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_botha, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxa, digits = 2),
'</br> Min Log Copies: ', round(both_ymina, digits = 2)),
name = "",
fillcolor = '#1B9E77',
line = list(color = '#1B9E77')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF A") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfa_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#1B9E77', size = 6, opacity = 0.65))
p_wrf_a
save(p_wrf_a, file = "./plotly_objs/p_wrf_a.rda")
#**************************************WRF B PLOT**********************************************
#add trendlines
#extract data from geom_smooth
#both extract
# *********************************span 0.6***********************************
#*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothb <- ggplot(wrfb_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothb<<-..y..), method = "loess", color = '#D95F02',
span = 0.25, n = 849)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothb
## `geom_smooth()` using formula 'y ~ x'
fit_bothb
## [1] 12.58914 12.58592 12.58276 12.57966 12.57664 12.57367 12.57078 12.56796
## [9] 12.56520 12.56251 12.55988 12.55733 12.55485 12.55243 12.55008 12.54781
## [17] 12.54560 12.54347 12.54140 12.53941 12.53748 12.53563 12.53385 12.53215
## [25] 12.53051 12.52895 12.52746 12.52605 12.52471 12.52344 12.52225 12.52113
## [33] 12.52008 12.51912 12.51822 12.51741 12.51667 12.51600 12.51542 12.51490
## [41] 12.51447 12.51412 12.51384 12.51365 12.51356 12.51358 12.51369 12.51390
## [49] 12.51420 12.51460 12.51509 12.51567 12.51634 12.51711 12.51796 12.51890
## [57] 12.51992 12.52103 12.52222 12.52349 12.52485 12.52628 12.52779 12.52938
## [65] 12.53104 12.53278 12.53459 12.53648 12.53843 12.54045 12.54254 12.54470
## [73] 12.54692 12.54921 12.55156 12.55397 12.55645 12.55898 12.56157 12.56422
## [81] 12.56692 12.56968 12.57249 12.57535 12.57826 12.58122 12.58423 12.58728
## [89] 12.59039 12.59353 12.59672 12.59995 12.60334 12.60701 12.61094 12.61513
## [97] 12.61955 12.62421 12.62907 12.63414 12.63941 12.64485 12.65046 12.65622
## [105] 12.66213 12.66816 12.67432 12.68058 12.68694 12.69338 12.69989 12.70645
## [113] 12.71307 12.71971 12.72638 12.73306 12.73973 12.74639 12.75303 12.75962
## [121] 12.76616 12.77264 12.77905 12.78536 12.79158 12.79769 12.80367 12.80951
## [129] 12.81521 12.82075 12.82611 12.83129 12.83627 12.84169 12.84809 12.85540
## [137] 12.86351 12.87231 12.88170 12.89160 12.90189 12.91248 12.92327 12.93416
## [145] 12.94504 12.95582 12.96640 12.97668 12.98655 12.99593 13.00470 13.01277
## [153] 13.02003 13.02640 13.03176 13.03603 13.04029 13.04566 13.05207 13.05941
## [161] 13.06761 13.07658 13.08624 13.09650 13.10727 13.11848 13.13004 13.14185
## [169] 13.15385 13.16593 13.17802 13.19004 13.20189 13.21349 13.22476 13.23561
## [177] 13.24595 13.25571 13.26479 13.27312 13.28060 13.28716 13.29270 13.29714
## [185] 13.30040 13.30239 13.30302 13.30222 13.29989 13.29584 13.28997 13.28241
## [193] 13.27326 13.26265 13.25067 13.23745 13.22309 13.20771 13.19141 13.17432
## [201] 13.15654 13.13819 13.11937 13.10021 13.08080 13.06127 13.04173 13.02228
## [209] 13.00305 12.98414 12.96566 12.94773 12.93045 12.91395 12.89833 12.88371
## [217] 12.87019 12.85602 12.83948 12.82082 12.80024 12.77797 12.75423 12.72923
## [225] 12.70321 12.67637 12.64895 12.62116 12.59323 12.56537 12.53780 12.51075
## [233] 12.48444 12.45908 12.43490 12.41213 12.39097 12.37165 12.35440 12.33942
## [241] 12.32576 12.31230 12.29903 12.28595 12.27306 12.26035 12.24782 12.23547
## [249] 12.22329 12.21129 12.19945 12.18778 12.17628 12.16493 12.15374 12.14270
## [257] 12.13182 12.12108 12.11049 12.10004 12.08973 12.08026 12.07226 12.06561
## [265] 12.06021 12.05594 12.05269 12.05034 12.04878 12.04791 12.04761 12.04776
## [273] 12.04826 12.04899 12.04984 12.05069 12.05144 12.05198 12.05218 12.05194
## [281] 12.05114 12.04968 12.04744 12.04431 12.04017 12.03491 12.02843 12.02147
## [289] 12.01484 12.00852 12.00247 11.99666 11.99107 11.98566 11.98041 11.97529
## [297] 11.97027 11.96532 11.96041 11.95551 11.95059 11.94562 11.94058 11.93543
## [305] 11.93014 11.92469 11.91905 11.91318 11.90707 11.90067 11.89313 11.88373
## [313] 11.87263 11.86000 11.84600 11.83080 11.81456 11.79746 11.77964 11.76129
## [321] 11.74256 11.72362 11.70464 11.68578 11.66721 11.64909 11.63159 11.61488
## [329] 11.59911 11.58446 11.57109 11.55916 11.54885 11.54031 11.53372 11.52924
## [337] 11.52702 11.52557 11.52335 11.52050 11.51713 11.51340 11.50942 11.50534
## [345] 11.50127 11.49737 11.49375 11.49055 11.48791 11.48595 11.48481 11.48462
## [353] 11.48551 11.48761 11.49106 11.49599 11.50253 11.51122 11.52240 11.53589
## [361] 11.55153 11.56915 11.58858 11.60966 11.63221 11.65608 11.68108 11.70706
## [369] 11.73385 11.76127 11.78916 11.81736 11.84569 11.87398 11.90207 11.92980
## [377] 11.95698 11.98346 12.00907 12.03363 12.05699 12.07897 12.09940 12.11812
## [385] 12.13496 12.15223 12.17216 12.19450 12.21896 12.24528 12.27318 12.30240
## [393] 12.33266 12.36369 12.39522 12.42698 12.45869 12.49009 12.52091 12.55087
## [401] 12.57970 12.60714 12.63290 12.65672 12.67834 12.69746 12.71384 12.72718
## [409] 12.73885 12.75033 12.76162 12.77269 12.78350 12.79403 12.80426 12.81416
## [417] 12.82371 12.83289 12.84165 12.84999 12.85788 12.86528 12.87218 12.87855
## [425] 12.88436 12.88958 12.89421 12.89819 12.90153 12.90417 12.90611 12.90732
## [433] 12.90776 12.90742 12.90627 12.90288 12.89609 12.88625 12.87370 12.85880
## [441] 12.84189 12.82333 12.80348 12.78267 12.76126 12.73961 12.71806 12.69696
## [449] 12.67667 12.65753 12.63990 12.62412 12.61056 12.59955 12.59145 12.58354
## [457] 12.57306 12.56025 12.54538 12.52869 12.51045 12.49091 12.47032 12.44895
## [465] 12.42704 12.40486 12.38266 12.36070 12.33923 12.31851 12.29879 12.28034
## [473] 12.26340 12.24824 12.23511 12.22426 12.21595 12.21044 12.20645 12.20253
## [481] 12.19872 12.19502 12.19146 12.18807 12.18487 12.18187 12.17910 12.17658
## [489] 12.17433 12.17238 12.17075 12.16945 12.16852 12.16796 12.16781 12.16809
## [497] 12.16881 12.17000 12.17168 12.17387 12.17660 12.17988 12.18374 12.18820
## [505] 12.19446 12.20359 12.21535 12.22955 12.24595 12.26436 12.28455 12.30631
## [513] 12.32942 12.35368 12.37886 12.40475 12.43114 12.45781 12.48455 12.51115
## [521] 12.53738 12.56303 12.58790 12.61176 12.63440 12.65560 12.67516 12.69285
## [529] 12.70847 12.72179 12.73261 12.74071 12.74810 12.75685 12.76682 12.77788
## [537] 12.78989 12.80271 12.81621 12.83024 12.84468 12.85937 12.87420 12.88901
## [545] 12.90367 12.91805 12.93201 12.94541 12.95810 12.96997 12.98086 12.99065
## [553] 12.99919 13.00635 13.01198 13.01596 13.01815 13.01840 13.01659 13.01256
## [561] 13.00580 12.99601 12.98345 12.96838 12.95104 12.93169 12.91059 12.88799
## [569] 12.86413 12.83928 12.81369 12.78761 12.76130 12.73500 12.70898 12.68348
## [577] 12.65875 12.63506 12.61266 12.59179 12.57272 12.55569 12.54097 12.52593
## [585] 12.50796 12.48733 12.46426 12.43902 12.41185 12.38300 12.35272 12.32125
## [593] 12.28885 12.25576 12.22223 12.18851 12.15485 12.12150 12.08870 12.05671
## [601] 12.02577 11.99614 11.96805 11.94176 11.91752 11.89557 11.87616 11.85955
## [609] 11.84598 11.83358 11.82037 11.80649 11.79205 11.77718 11.76200 11.74662
## [617] 11.73119 11.71580 11.70060 11.68569 11.67120 11.65726 11.64398 11.63148
## [625] 11.61990 11.60934 11.59994 11.59181 11.58508 11.57987 11.57630 11.57449
## [633] 11.57486 11.57762 11.58257 11.58952 11.59826 11.60860 11.62035 11.63330
## [641] 11.64727 11.66204 11.67744 11.69326 11.70930 11.72537 11.74127 11.75680
## [649] 11.77177 11.78598 11.79924 11.81134 11.82209 11.83322 11.84647 11.86169
## [657] 11.87874 11.89746 11.91770 11.93931 11.96214 11.98604 12.01086 12.03644
## [665] 12.06264 12.08930 12.11627 12.14341 12.17055 12.19756 12.22427 12.25055
## [673] 12.27623 12.30116 12.32521 12.34820 12.37000 12.39045 12.40940 12.42670
## [681] 12.44220 12.45691 12.47194 12.48725 12.50279 12.51854 12.53444 12.55046
## [689] 12.56657 12.58273 12.59888 12.61501 12.63107 12.64702 12.66282 12.67843
## [697] 12.69382 12.70895 12.72378 12.73827 12.75238 12.76607 12.77931 12.79206
## [705] 12.80427 12.81592 12.82696 12.83748 12.84763 12.85741 12.86686 12.87598
## [713] 12.88479 12.89332 12.90157 12.90957 12.91734 12.92489 12.93224 12.93940
## [721] 12.94640 12.95326 12.95999 12.96660 12.97312 12.97957 12.98596 12.99231
## [729] 12.99864 13.00496 13.01131 13.01768 13.02404 13.03037 13.03665 13.04286
## [737] 13.04896 13.05494 13.06077 13.06642 13.07187 13.07709 13.08207 13.08678
## [745] 13.09119 13.09527 13.09901 13.10238 13.10535 13.10790 13.11001 13.11164
## [753] 13.11280 13.11351 13.11381 13.11370 13.11323 13.11242 13.11129 13.10988
## [761] 13.10820 13.10628 13.10416 13.10185 13.09939 13.09679 13.09409 13.09131
## [769] 13.08848 13.08562 13.08277 13.07994 13.07716 13.07447 13.07188 13.06942
## [777] 13.06712 13.06482 13.06233 13.05966 13.05682 13.05380 13.05063 13.04728
## [785] 13.04379 13.04013 13.03633 13.03239 13.02831 13.02409 13.01975 13.01527
## [793] 13.01068 13.00597 13.00115 12.99622 12.99118 12.98605 12.98083 12.97551
## [801] 12.97011 12.96463 12.95907 12.95344 12.94775 12.94199 12.93614 12.93016
## [809] 12.92404 12.91780 12.91144 12.90495 12.89833 12.89159 12.88473 12.87774
## [817] 12.87064 12.86342 12.85608 12.84862 12.84104 12.83336 12.82555 12.81764
## [825] 12.80961 12.80147 12.79322 12.78487 12.77642 12.76789 12.75928 12.75059
## [833] 12.74181 12.73294 12.72398 12.71493 12.70578 12.69653 12.68718 12.67773
## [841] 12.66817 12.65850 12.64872 12.63882 12.62881 12.61868 12.60843 12.59805
## [849] 12.58755
#assign fits to a vector
both_trendb <- fit_bothb
#extract y min and max for each
limits_bothb <- ggplot_build(extract_bothb)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothb <- as.data.frame(limits_bothb)
both_yminb <- limits_bothb$ymin
both_ymaxb <- limits_bothb$ymax
#reassign dataframes (just to be safe)
work_bothb <- wrfb_both
#fill in missing dates to smooth fits
work_bothb <- work_bothb %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothb <- work_bothb$date
#create a new smooth dataframe to layer
smooth_frame_bothb <- data.frame(date_vec_bothb, both_trendb, both_yminb, both_ymaxb)
#WRF B
#plot smooth frames
p_wrf_b <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothb, y = ~both_trendb,
data = smooth_frame_bothb,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb,
'</br> Median Log Copies: ', round(both_trendb, digits = 2)),
line = list(color = '#D95F02', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothb, ymin = ~both_yminb, ymax = ~both_ymaxb,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothb, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxb, digits = 2),
'</br> Min Log Copies: ', round(both_yminb, digits = 2)),
name = "",
fillcolor = '#D95F02',
line = list(color = '#D95F02')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF B") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfb_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#D95F02', size = 6, opacity = 0.65))
p_wrf_b
save(p_wrf_b, file = "./plotly_objs/p_wrf_b.rda")
#**************************************WRF C PLOT********************************************** #add trendlines #extract data from geom_smooth # *********************************span 0.6*********************************** #*****************Must always update the n = TOTAL NUMBER OF DAYS*************************
extract_bothc <- ggplot(wrfc_both, aes(x = date, y = log_total_copies_both)) +
stat_smooth(aes(outfit=fit_bothc<<-..y..), method = "loess", color = '#E7298A',
span = 0.25, n = 849)
## Warning: Ignoring unknown aesthetics: outfit
#look at the fits to align dates and total observations
#both
extract_bothc
## `geom_smooth()` using formula 'y ~ x'
fit_bothc
## [1] 12.04523 12.03875 12.03237 12.02608 12.01988 12.01378 12.00778 12.00187
## [9] 11.99605 11.99033 11.98470 11.97917 11.97373 11.96838 11.96312 11.95796
## [17] 11.95289 11.94791 11.94302 11.93822 11.93351 11.92889 11.92436 11.91993
## [25] 11.91558 11.91132 11.90715 11.90306 11.89907 11.89516 11.89134 11.88761
## [33] 11.88397 11.88041 11.87694 11.87355 11.87025 11.86704 11.86391 11.86086
## [41] 11.85790 11.85503 11.85223 11.84953 11.84690 11.84436 11.84190 11.83952
## [49] 11.83723 11.83501 11.83290 11.83091 11.82905 11.82730 11.82568 11.82417
## [57] 11.82278 11.82151 11.82036 11.81932 11.81839 11.81757 11.81687 11.81628
## [65] 11.81579 11.81542 11.81515 11.81499 11.81493 11.81498 11.81513 11.81538
## [73] 11.81573 11.81619 11.81674 11.81739 11.81813 11.81897 11.81991 11.82094
## [81] 11.82206 11.82327 11.82457 11.82596 11.82744 11.82901 11.83066 11.83240
## [89] 11.83422 11.83613 11.83811 11.84018 11.84232 11.84455 11.84685 11.84923
## [97] 11.85168 11.85421 11.85681 11.85955 11.86249 11.86561 11.86893 11.87243
## [105] 11.87611 11.87997 11.88399 11.88817 11.89252 11.89702 11.90166 11.90645
## [113] 11.91138 11.91645 11.92164 11.92696 11.93240 11.93795 11.94361 11.94938
## [121] 11.95524 11.96120 11.96726 11.97339 11.97961 11.98590 11.99226 11.99869
## [129] 12.00517 12.01172 12.01831 12.02495 12.03163 12.03834 12.04509 12.05313
## [137] 12.06359 12.07622 12.09078 12.10704 12.12474 12.14367 12.16357 12.18420
## [145] 12.20533 12.22671 12.24811 12.26929 12.29001 12.31002 12.32909 12.34698
## [153] 12.36345 12.37826 12.39117 12.40195 12.41239 12.42440 12.43785 12.45262
## [161] 12.46861 12.48568 12.50372 12.52261 12.54224 12.56248 12.58321 12.60432
## [169] 12.62569 12.64721 12.66874 12.69017 12.71139 12.73228 12.75271 12.77257
## [177] 12.79174 12.81010 12.82754 12.84393 12.85915 12.87309 12.88563 12.89665
## [185] 12.90604 12.91366 12.91941 12.92317 12.92481 12.92427 12.92163 12.91702
## [193] 12.91057 12.90239 12.89263 12.88139 12.86881 12.85502 12.84013 12.82428
## [201] 12.80759 12.79019 12.77220 12.75374 12.73495 12.71594 12.69685 12.67780
## [209] 12.65892 12.64032 12.62214 12.60451 12.58754 12.57137 12.55611 12.54190
## [217] 12.52886 12.51510 12.49880 12.48019 12.45949 12.43693 12.41275 12.38717
## [225] 12.36042 12.33274 12.30434 12.27546 12.24633 12.21718 12.18823 12.15972
## [233] 12.13187 12.10492 12.07909 12.05460 12.03170 12.01061 11.99156 11.97477
## [241] 11.95914 11.94340 11.92758 11.91169 11.89576 11.87981 11.86385 11.84791
## [249] 11.83201 11.81616 11.80039 11.78472 11.76916 11.75374 11.73847 11.72339
## [257] 11.70850 11.69383 11.67939 11.66521 11.65131 11.63784 11.62491 11.61249
## [265] 11.60056 11.58908 11.57802 11.56736 11.55706 11.54709 11.53742 11.52802
## [273] 11.51887 11.50993 11.50117 11.49256 11.48407 11.47567 11.46733 11.45902
## [281] 11.45071 11.44237 11.43397 11.42548 11.41687 11.40811 11.39916 11.39039
## [289] 11.38213 11.37436 11.36705 11.36017 11.35368 11.34755 11.34176 11.33627
## [297] 11.33106 11.32608 11.32132 11.31673 11.31229 11.30797 11.30373 11.29955
## [305] 11.29540 11.29123 11.28703 11.28276 11.27839 11.27389 11.26862 11.26205
## [313] 11.25429 11.24547 11.23572 11.22515 11.21390 11.20209 11.18983 11.17726
## [321] 11.16450 11.15167 11.13890 11.12630 11.11402 11.10215 11.09085 11.08021
## [329] 11.07038 11.06147 11.05361 11.04691 11.04152 11.03754 11.03511 11.03434
## [337] 11.03537 11.03732 11.03930 11.04134 11.04350 11.04581 11.04832 11.05109
## [345] 11.05414 11.05753 11.06131 11.06551 11.07019 11.07538 11.08114 11.08751
## [353] 11.09454 11.10226 11.11073 11.11999 11.13009 11.14199 11.15652 11.17348
## [361] 11.19270 11.21399 11.23717 11.26204 11.28843 11.31614 11.34500 11.37482
## [369] 11.40542 11.43660 11.46818 11.49999 11.53183 11.56351 11.59486 11.62569
## [377] 11.65581 11.68504 11.71319 11.74008 11.76552 11.78933 11.81133 11.83132
## [385] 11.84912 11.86669 11.88598 11.90679 11.92894 11.95224 11.97651 12.00155
## [393] 12.02719 12.05323 12.07949 12.10578 12.13191 12.15769 12.18294 12.20747
## [401] 12.23110 12.25363 12.27487 12.29465 12.31278 12.32906 12.34331 12.35534
## [409] 12.36595 12.37605 12.38566 12.39479 12.40344 12.41162 12.41936 12.42664
## [417] 12.43349 12.43991 12.44591 12.45150 12.45669 12.46149 12.46591 12.46996
## [425] 12.47365 12.47698 12.47997 12.48263 12.48496 12.48698 12.48869 12.49010
## [433] 12.49122 12.49207 12.49265 12.49206 12.48952 12.48522 12.47934 12.47207
## [441] 12.46360 12.45411 12.44380 12.43284 12.42143 12.40975 12.39799 12.38634
## [449] 12.37497 12.36409 12.35388 12.34452 12.33620 12.32910 12.32343 12.31739
## [457] 12.30923 12.29915 12.28735 12.27404 12.25941 12.24367 12.22701 12.20965
## [465] 12.19177 12.17359 12.15531 12.13712 12.11923 12.10184 12.08515 12.06937
## [473] 12.05469 12.04131 12.02945 12.01930 12.01105 12.00492 11.99964 11.99386
## [481] 11.98764 11.98104 11.97415 11.96701 11.95971 11.95231 11.94487 11.93747
## [489] 11.93017 11.92303 11.91613 11.90953 11.90331 11.89751 11.89223 11.88751
## [497] 11.88343 11.88006 11.87746 11.87570 11.87485 11.87498 11.87614 11.87842
## [505] 11.88239 11.88849 11.89656 11.90644 11.91798 11.93103 11.94542 11.96101
## [513] 11.97762 11.99512 12.01333 12.03211 12.05130 12.07074 12.09028 12.10976
## [521] 12.12902 12.14790 12.16626 12.18393 12.20076 12.21659 12.23127 12.24463
## [529] 12.25653 12.26680 12.27529 12.28185 12.28794 12.29508 12.30317 12.31210
## [537] 12.32178 12.33212 12.34301 12.35436 12.36606 12.37802 12.39015 12.40233
## [545] 12.41449 12.42650 12.43829 12.44975 12.46078 12.47128 12.48116 12.49031
## [553] 12.49865 12.50606 12.51246 12.51774 12.52181 12.52456 12.52591 12.52574
## [561] 12.52414 12.52128 12.51728 12.51222 12.50621 12.49933 12.49168 12.48337
## [569] 12.47447 12.46510 12.45535 12.44530 12.43507 12.42474 12.41441 12.40417
## [577] 12.39413 12.38437 12.37500 12.36610 12.35778 12.35014 12.34325 12.33557
## [585] 12.32556 12.31343 12.29936 12.28354 12.26615 12.24740 12.22746 12.20652
## [593] 12.18478 12.16242 12.13963 12.11661 12.09353 12.07059 12.04797 12.02587
## [601] 12.00448 11.98398 11.96456 11.94641 11.92972 11.91468 11.90148 11.89030
## [609] 11.88133 11.87311 11.86409 11.85437 11.84407 11.83329 11.82213 11.81069
## [617] 11.79909 11.78742 11.77579 11.76431 11.75308 11.74220 11.73178 11.72192
## [625] 11.71273 11.70432 11.69678 11.69022 11.68475 11.68047 11.67748 11.67590
## [633] 11.67612 11.67834 11.68240 11.68812 11.69532 11.70382 11.71345 11.72404
## [641] 11.73540 11.74736 11.75975 11.77238 11.78509 11.79769 11.81001 11.82188
## [649] 11.83311 11.84353 11.85297 11.86124 11.86817 11.87505 11.88321 11.89256
## [657] 11.90299 11.91441 11.92674 11.93986 11.95370 11.96815 11.98312 11.99851
## [665] 12.01422 12.03017 12.04626 12.06238 12.07846 12.09438 12.11006 12.12540
## [673] 12.14031 12.15469 12.16844 12.18147 12.19369 12.20500 12.21530 12.22450
## [681] 12.23250 12.23985 12.24712 12.25432 12.26145 12.26851 12.27548 12.28238
## [689] 12.28920 12.29594 12.30259 12.30915 12.31563 12.32201 12.32830 12.33450
## [697] 12.34059 12.34659 12.35248 12.35827 12.36395 12.36953 12.37500 12.38035
## [705] 12.38559 12.39071 12.39571 12.40038 12.40455 12.40825 12.41152 12.41440
## [713] 12.41693 12.41915 12.42109 12.42281 12.42434 12.42572 12.42698 12.42818
## [721] 12.42934 12.43050 12.43172 12.43302 12.43445 12.43604 12.43784 12.43989
## [729] 12.44222 12.44487 12.44773 12.45063 12.45356 12.45651 12.45947 12.46241
## [737] 12.46534 12.46824 12.47109 12.47389 12.47661 12.47925 12.48179 12.48422
## [745] 12.48654 12.48871 12.49074 12.49261 12.49431 12.49582 12.49713 12.49827
## [753] 12.49929 12.50018 12.50096 12.50163 12.50219 12.50265 12.50302 12.50330
## [761] 12.50350 12.50362 12.50366 12.50364 12.50356 12.50342 12.50324 12.50300
## [769] 12.50273 12.50242 12.50208 12.50172 12.50134 12.50095 12.50055 12.50015
## [777] 12.49976 12.49934 12.49887 12.49836 12.49779 12.49718 12.49651 12.49580
## [785] 12.49504 12.49424 12.49338 12.49248 12.49153 12.49053 12.48949 12.48840
## [793] 12.48726 12.48608 12.48485 12.48358 12.48226 12.48089 12.47948 12.47803
## [801] 12.47653 12.47498 12.47340 12.47176 12.47009 12.46837 12.46661 12.46481
## [809] 12.46297 12.46108 12.45915 12.45717 12.45515 12.45308 12.45097 12.44880
## [817] 12.44659 12.44432 12.44200 12.43963 12.43720 12.43472 12.43219 12.42959
## [825] 12.42694 12.42423 12.42146 12.41863 12.41574 12.41279 12.40979 12.40674
## [833] 12.40364 12.40048 12.39727 12.39401 12.39069 12.38733 12.38391 12.38045
## [841] 12.37693 12.37336 12.36975 12.36608 12.36237 12.35861 12.35480 12.35094
## [849] 12.34704
#assign fits to a vector
both_trendc <- fit_bothc
#extract y min and max for each
limits_bothc <- ggplot_build(extract_bothc)$data
## `geom_smooth()` using formula 'y ~ x'
limits_bothc <- as.data.frame(limits_bothc)
both_yminc <- limits_bothc$ymin
both_ymaxc <- limits_bothc$ymax
#reassign dataframes (just to be safe)
work_bothc <- wrfc_both
#fill in missing dates to smooth fits
work_bothc <- work_bothc %>% complete(date = seq(min(date), max(date), by = "1 day"))
date_vec_bothc <- work_bothc$date
#create a new smooth dataframe to layer
smooth_frame_bothc <- data.frame(date_vec_bothc, both_trendc, both_yminc, both_ymaxc)
#WRF C
#plot smooth frames
p_wrf_c <- plotly::plot_ly() %>%
plotly::add_lines(x = ~date_vec_bothc, y = ~both_trendc,
data = smooth_frame_bothc,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc,
'</br> Median Log Copies: ', round(both_trendc, digits = 2)),
line = list(color = '#E7298A', size = 8, opacity = 0.65),
showlegend = FALSE) %>%
layout(xaxis = list(range = c(mindate - 7, maxdate + 7))) %>% #buffer here
plotly::add_ribbons(x ~date_vec_bothc, ymin = ~both_yminc, ymax = ~both_ymaxc,
showlegend = FALSE,
opacity = 0.25,
hoverinfo = "text",
text = ~paste('</br> Date: ', date_vec_bothc, #leaving in case we want to change
'</br> Max Log Copies: ', round(both_ymaxc, digits = 2),
'</br> Min Log Copies: ', round(both_yminc, digits = 2)),
name = "",
fillcolor = '#E7298A',
line = list(color = '#E7298A')) %>%
layout(yaxis = list(title = "Total Log10 SARS CoV-2 Copies",
showline = TRUE,
automargin = TRUE)) %>%
layout(xaxis = list(title = "Date")) %>%
layout(title = "WRF C") %>%
plotly::add_markers(x = ~date, y = ~log_total_copies_both,
data = wrfc_both,
hoverinfo = "text",
showlegend = FALSE,
text = ~paste('</br> Date: ', date,
'</br> Actual Log Copies: ', round(log_total_copies_both, digits = 2)),
marker = list(color = '#E7298A', size = 6, opacity = 0.65))
p_wrf_c
save(p_wrf_c, file = "./plotly_objs/p_wrf_c.rda")
save(wrfa_both, file = "./plotly_objs/wrfa_both.rda")
save(wrfb_both, file = "./plotly_objs/wrfb_both.rda")
save(wrfc_both, file = "./plotly_objs/wrfc_both.rda")
save(date_vec_botha, file = "./plotly_objs/date_vec_botha.rda")
save(date_vec_bothb, file = "./plotly_objs/date_vec_bothb.rda")
save(date_vec_bothc, file = "./plotly_objs/date_vec_bothc.rda")
save(both_ymina, file = "./plotly_objs/both_ymina.rda")
save(both_ymaxa, file = "./plotly_objs/both_ymaxa.rda")
save(both_yminb, file = "./plotly_objs/both_yminb.rda")
save(both_ymaxb, file = "./plotly_objs/both_ymaxb.rda")
save(both_yminc, file = "./plotly_objs/both_yminc.rda")
save(both_ymaxc, file = "./plotly_objs/both_ymaxc.rda")